<template>
  <div v-if="!changePage">
    <common-search :show-item="2" :showItem="2" :col-layout="{xxl: 6, xl:8, lg: 8, md: 12, sm: 24, xs: 24}" v-model="query" :formItems="formItems" @search="search" @reset="reset"></common-search>
    <a-button type="primary" @click="exports" :loading="exportLoading" v-modulePerm="['performanceReview:export']">
      <template #icon>
        <ExportOutlined />
      </template>
      导出
    </a-button>
    <a-button style="margin-left: 10px" type="primary" @click="$router.push('/inventoryPools/candidateInventory')" v-modulePerm="['performanceReview:export']">
      候选库存
    </a-button>
    <common-table
        :columns="columns"
        :dataSource="dataList"
        v-model:localPagination="page"
        @paginationChange="onPageChange"
        v-model:loading="loading"
        :rowKey="(record) => record.supplierCode"
        :scroll="{ x: 'max-content'}"
        :row-key="(record) => record.sku"
        :slots="['orderId','saleOrderCode']"
    >
      <template #orderId="{record}">
        <a @click="$router.push({path:'/orderStandardization/orderDetail',query:{id:record.orderId}})">{{record.orderId}}</a>
      </template>
      <template #saleOrderCode="{record}">
        <a v-if="modulePerm(['performanceReview:edit'])" @click="goInt(record.saleOrderCode)">{{record.saleOrderCode}}</a>
        <span v-else>{{record.saleOrderCode}}</span>
      </template>
      <!--    <template #action="{record}">-->
      <!--      <a @click="$router.push({path:'/inventoryPools/reviewList',query:{orderId:record.orderId}})">重新审单</a>-->
      <!--    </template>-->
    </common-table>
  </div>
  <div v-else>
    <Review :orderId="orderId" @out="out"/>
  </div>
</template>
<script>
export default {
  name:"inventoryPools-performanceReview"
}
</script>
<script setup>
import CommonSearch from "@/components/commonSearch/index.vue";
import CommonTable from "@/components/commonTable/index.vue";
import {useSearchTable} from "@/hooks/table/useSearchTable";
import {ref,onMounted} from "vue";
import {getPerformancePage} from "@/api/inventoryPools/performanceReview.js";
import {message} from "ant-design-vue";
import {postFile} from "@utils/service/index.js";
import {getManyDictItems} from "@/api/system/dict.js";
import Review from './components/review.vue'
import {modulePerm} from "@utils/modulePerm.js";
const { dataList, query, loading, page, search, reset, onPageChange } = useSearchTable({
  searchAPI: getPerformancePage,
  queryFactory: () => ({
    status: '',
  }),
  beforeSearch: () => {
    //处理日期
    if(query.value.time){
      query.value.orderCreateTimeStart = query.value.time[0]
      query.value.orderCreateTimeEnd = query.value.time[1]
    }else{
      delete query.value.orderCreateTimeStart
      delete query.value.orderCreateTimeEnd
    }
  },
});
const orderId = ref('')
const formItems = ref([
  {
    label:'易仓订单',
    type:'input',
    field:'saleOrderCode',
  },
  {
    label:"平台SKU",
    type:'input',
    field: 'productSku',
  },
  {
    label:"平台订单",
    type:'input',
    field: 'orderId',
  },
  {
    label:'仓库SKU',
    type:'input',
    field:'warehouseSku',
  },
  {
    label:'站点',
    type:'select',
    field:'site',
    options: [],
  },
  {
    label:'销售平台',
    type:'select',
    field:'platform',
    options:[]
  },
  {
    label:'订单时间',
    type:'rangePicker',
    field:'time',
    showTime: false,
    defaultValue: []
  },
  {
    label:"销售区域",
    type:'select',
    field: 'saleZone',
    options:[]
  },
  {
    label:"库存池",
    type:'input',
    field: 'poolCode',
  },
  {
    label:'预计发货仓库',
    type:'input',
    field:'warehouseCode',
  },
  {
    label:'需调整版本',
    type:'select',
    field:'needChangeVersion',
    options:[]
  },
  {
    label:"总体状态",
    type:'select',
    field: 'ofcOrderStatus',
    options:[]
  },
  {
    label:"物流服务",
    type:'input',
    field: 'specialService',
  },
  {
    label:'物流类型',
    type:'input',
    field:'deliveryType',
  },
  {
    label:'散件',
    type:'select',
    field:'isSpare',
    options:[]
  },
])
const changePage = ref(false)
const columns = [
  {
    "dataIndex": "site",
    "groupTitle": "",
    "title": "站点",
    "align": "center",
    "fieldType": "String",
    fixed: "left"
  },
  {
    fixed: "left",
    "dataIndex": "saleOrderCode",
    "groupTitle": "",
    "title": "易仓订单",
    "align": "center",
    "fieldType": "String"
  },
  {
    "dataIndex": "orderId",
    "groupTitle": "",
    "title": "平台订单",
    "align": "center",
    "fieldType": "String"
  },
  {
    "dataIndex": "saleZone",
    "groupTitle": "",
    "title": "销售区域",
    "align": "center",
    "fieldType": "String"
  },
  {
    "dataIndex": "platform",
    "groupTitle": "",
    "title": "销售平台",
    "align": "center",
    "fieldType": "String"
  },
  {
    "dataIndex": "ofcOrderStatus_dictText",
    "groupTitle": "",
    "title": "总体状态",
    "align": "center",
    "fieldType": "String"
  },
  {
    title:'订单进程',
    align: 'center',
    children: [
      {
        "dataIndex": "readyCnt",
        "title": "可标发数",
        "align": "center",
        "fieldType": "Long"
      },
      {
        "dataIndex": "shippingCnt",
        "title": "海上数",
        "align": "center",
        "fieldType": "Long"
      },
      {
        "dataIndex": "foshanCnt",
        "title": "佛山数",
        "align": "center",
        "fieldType": "Long"
      },
      {

        "dataIndex": "purchaseCnt",
        "title": "采购数",
        "align": "center",
        "fieldType": "Long"
      },
      {

        "dataIndex": "stockoutCnt",
        "title": "缺货数",
        "align": "center",
        "fieldType": "Long"
      },
    ]
  },
  {

    "dataIndex": "warehouseSku",
    "groupTitle": "",
    "title": "仓库SKU",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "qty",
    "groupTitle": "",
    "title": "数量",
    "align": "center",
    "fieldType": "Long"
  },
  {

    "dataIndex": "lineStatus",
    "groupTitle": "",
    "title": "本行状态",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "productSku",
    "groupTitle": "",
    "title": "平台SKU",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "poolCode",
    "groupTitle": "",
    "title": "库存池",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "warehouseCode",
    "groupTitle": "",
    "title": "预计发货仓库",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "orderCreateTime",
    "groupTitle": "",
    "title": "订单时间",
    "align": "center",
    "fieldType": "Date"
  },
  {
    "dataIndex": "etaDate",
    "groupTitle": "",
    "title": "到港ETA",
    "align": "center",
    "fieldType": "String"
  },
  {
    "dataIndex": "sellableDate",
    "groupTitle": "",
    "title": "上架ETA",
    "align": "center",
    "fieldType": "String"
  },
  {
    "dataIndex": "earliestSendout",
    "groupTitle": "",
    "title": "最早标发",
    "align": "center",
    "fieldType": "Date"
  },
  {
    "dataIndex": "latestSendout",
    "groupTitle": "",
    "title": "最迟标发",
    "align": "center",
    "fieldType": "Date"
  },
  {

    "dataIndex": "evaDelivery",
    "groupTitle": "",
    "title": "交期",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "sourceVersion",
    "groupTitle": "",
    "title": "易仓版本",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "chVerion",
    "groupTitle": "",
    "title": "计算版本",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "needChangeVersion",
    "groupTitle": "",
    "title": "需调整版本",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "specialService",
    "groupTitle": "",
    "title": "物流服务",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "deliveryType",
    "groupTitle": "",
    "title": "物流类型",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "isSpare_dictText",
    "groupTitle": "",
    "title": "散件",
    "align": "center",
    "fieldType": "String"
  },
  {
    "dataIndex": "suggestDeliveryType",
    "groupTitle": "",
    "title": "建议物流类型",
    "align": "center",
    "fieldType": "String"
  },
  {
    "dataIndex": "suggestDeliveryRemark",
    "groupTitle": "",
    "title": "建议物流备注",
    "align": "center",
    "fieldType": "String"
  },
  // {
  //   "dataIndex": "action",
  //   "title": "操作",
  //   "align": "center",
  //   fixed: "right",
  // }
]
const exportLoading = ref(false);
const exports = async () => {
  try{
    exportLoading.value = true;
    const res = await postFile('/inventoryPool/verify/export','post',query.value,'履约审单明细.xlsx')
    message.success('导出成功')
  }catch (e) {
    message.error(e);
  }finally {
    exportLoading.value = false;
  }
}
const out = () => {
  changePage.value = false;
  orderId.value = ''
  search()
}
const goInt = (id) => {
  changePage.value = true;
  console.log(id)
  orderId.value = id
}
/**
 * 初始化字典数据
 * @returns {Promise<void>}
 */
const init = async () => {
  try{
    const res = await getManyDictItems({
      dictCodeList:"site,boolean_cn,sale_area,platforms,ofc_order_status"
    })
    formItems.value[4].options = res.result.site
    formItems.value[14].options = res.result.boolean_cn
    formItems.value[7].options = res.result.sale_area
    formItems.value[5].options = res.result.platforms
    formItems.value[11].options = res.result.ofc_order_status
    formItems.value[10].options = res.result.boolean_cn
  }catch (e){
    console.log(e)
  }
}
onMounted(() => {
  init()
})
</script>
<style scoped>

</style>
